home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 003 / gothic / gothic0.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  3KB  |  171 lines

  1.  
  2. /*
  3.  *        G o t h i c   P r i n t e r
  4.  *
  5.  */
  6.  
  7. /*
  8.  * Courtesy of RTW
  9.  *
  10.  * Compile with gottab.c
  11.  *
  12.  * Prints the arguments, if none, it prompts for an output file and
  13.  * reads stdin.
  14.  *
  15.  *    If the first argument is -h, the display is halved.
  16.  *
  17.  *    / in the text reverses the background
  18.  *
  19.  * The following characters are displayed:
  20.  *
  21.  *    #.(@!$);-,?:'"  A-Z  a-z  0-9
  22.  *
  23.  * All others become blanks.
  24.  *
  25.  */
  26. #include <stdio.h>
  27.  
  28. char        outbuf[133];
  29. char        line[133];
  30. int        background    = 0;        /* Background color    */
  31. int        half        = 0;        /* Set to halve display    */
  32.  
  33. main (argc, argv)
  34. int        argc;
  35. char        *argv[];
  36.  
  37. {
  38.     register int        i;
  39.  
  40.     if (argc > 1 && argv[1][0] == '-' && (argv[1][1] | 040) == 'h') {
  41.         argc--;
  42.         argv++;
  43.         half++;
  44.     }
  45.     if (argc <= 1) {
  46.         printf("Gothic output file <terminal>: ");
  47.         fflush(stdout);
  48.         if (fgets(outbuf, sizeof outbuf, stdin) == NULL) {
  49.             panic("No output file", NULL);
  50.         }
  51.         outbuf[strlen(outbuf)-1] = NULL;
  52.         if (half == 0) {
  53.             printf("Half size (Yes/No) <N>: ");
  54.             fflush(stdout);
  55.             if (fgets(line, sizeof line, stdin) == NULL) {
  56.                 panic("Unexpected EOF", NULL);
  57.             }
  58.             line[strlen(line)-1] = NULL;
  59.             if ((line[0] | 040) == 'y')
  60.                 half++;
  61.         }
  62. #ifdef AMIGA
  63.         printf ("Use Cntrl-\\ to terminate input\n");
  64. #endif AMIGA
  65.         if (outbuf[0] != 0) {
  66.             if (freopen(outbuf, "w", stdout) == NULL)
  67.                 panic("Can't open", outbuf);
  68.         }
  69.         while (fgets(line, sizeof line, stdin) != NULL) {
  70.             line[strlen(line)-1] = NULL;
  71.             dotext(line);
  72.         }
  73.     }
  74.     else {
  75.         for (i = 1; i < argc; i++) {
  76.             dotext(argv[i]);
  77.         }
  78.         puts("\f");
  79.     }
  80. }
  81.  
  82. dotext(text)
  83. char        *text;
  84. /*
  85.  * Convert text to gothic letters, write them to stdout
  86.  */
  87. {
  88.     register char    *tp;
  89.     register int    c;
  90.  
  91.     for (tp = text; (c = *tp++) != 0;) {
  92.         if (c == '/')
  93.             background = (background) ? 0 : 2;
  94.         else    gothic(c);
  95.     }
  96. }
  97.  
  98. gothic(character)
  99. int        character;
  100. /*
  101.  * Process the character
  102.  */
  103. {
  104.     char            *gp;
  105.     register char        *op;
  106.     register int        i;
  107.     register int        byte;
  108.     int            index;
  109.     extern char        *gottab[];
  110.     int            lhalf;        /* Line half flag    */
  111.     int            chalf;        /* Column half flag    */
  112.         
  113.     index = (background) ? -1 : 0;
  114.     lhalf = chalf = 0;
  115.     gp = gottab[character & 127];
  116.     op = outbuf;
  117.     for (;;) {
  118.         if ((i = (*gp++ & 0377)) >= 254) {
  119.             if (background) {
  120.                 while (op < &outbuf[132])
  121.                     *op++ = 'X';
  122.             }
  123.             *op = 0;
  124.             lhalf = ~lhalf;
  125.             chalf = 0;
  126.             if (half) {
  127.                 if (lhalf) {
  128.                     outbuf[132 / 2] = 0;
  129.                     puts(outbuf);
  130.                 }
  131.             }
  132.             else {
  133.                 puts(outbuf);
  134.             }
  135.             op = outbuf;
  136.             if (i == 255)
  137.                 break;
  138.         }
  139.         else {
  140.             byte = "O X "[background - (index = (-1 - index))];
  141.             while (--i >= 0) {
  142.                 if (half) {
  143.                     chalf = ~chalf;
  144.                     if (chalf) {
  145.                         *op++ = byte;
  146.                     }
  147.                 }
  148.                 else {
  149.                     *op++ = byte;
  150.                 }
  151.             }
  152.             if (op >= &outbuf[132])
  153.                 panic("big line", NULL);
  154.         }
  155.     }
  156. }
  157.  
  158. panic(s, arg)
  159. char        *s;
  160. char        *arg;
  161. /*
  162.  * Fatal error exit
  163.  */
  164. {
  165.     fprintf(stderr, "gothic: %s", s);
  166.     if (arg != NULL)
  167.         fprintf(stderr, ": \"%s\"", arg);
  168.     fprintf(stderr, "\n");
  169.     exit(1);
  170. }
  171.